/**
 * 
 */
package zhoujian.oj.leetcode;

import org.junit.Test;

/**
 * @author hyper
 * @email zjkermit@gmail.com
 * @date Dec 19, 2013
 * @version 1.0
 * @description 
 * 		Determine whether an integer is a palindrome. 
 * 		Do this without extra space.
 */
public class PalindromeNumber {

	public boolean isPalindrome(int x) {
		if (x < 0) {
			return false;
		}
		
		int div = 1;
		while (x / div > 9) {
			div *= 10;
		}
		
		while (x != 0) {
			if (x / div != x % 10) {
				return false;
			}
			
			x = (x % div) / 10;
			div /= 100;
		}
		
		return true;
	}
	
	@Test
	public void testIsPalindrome() {
		assert isPalindrome(121);
		assert isPalindrome(1221);
		assert isPalindrome(12321);
		assert isPalindrome(111);
		assert isPalindrome(11);
		assert isPalindrome(1);
	}
	
}
